package com.atguigu.spzx.manage.controller;


import com.atguigu.spzx.manage.service.FeedbackService;
import com.atguigu.spzx.model.dto.system.FeedbackDto;
import com.atguigu.spzx.model.entity.system.Feedback;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/admin/system/feedback")
@Slf4j
@Tag(name = "用户管理接口")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;


    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findByPage(FeedbackDto feedbackDto ,
                                                @PathVariable(value = "pageNum") Integer pageNum ,
                                                @PathVariable(value = "pageSize") Integer pageSize) {
        log.info("用户查询内容:{},页码:{},页数:{}",feedbackDto,pageNum,pageSize);
        PageInfo<Feedback> pageInfo = feedbackService.findByPage(feedbackDto , pageNum , pageSize) ;
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "标记热门")
    @PutMapping(value = "/markPopularById/{feedbackId}")
    public Result markPopularById(@PathVariable(value = "feedbackId") Long id) {
        feedbackService.markPopularById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "关闭热门")
    @PutMapping(value = "/closePopularById/{feedbackId}")
    public Result closePopularById(@PathVariable(value = "feedbackId") Long id) {
        feedbackService.closePopularById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "删除评论")
    @DeleteMapping(value = "/deleteById/{feedbackId}")
    public Result deleteById(@PathVariable(value = "feedbackId") Long id) {
        feedbackService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }






}
